package cn.softcits.thread.ticket;

/**
 * @author Rocket
 * @version 10.0.1
 * @date 2021-07-04 1:31 PM
 */
public class SellThread extends Thread {

    private Ticket ticket;

    public SellThread(String name, Ticket ticket) {
        this.setName(name);
        this.ticket = ticket;
    }

    @Override
    public  void run() {

        while (ticket.getAmount() > 0) {
            synchronized (ticket) {
                ticket.setAmount(ticket.getAmount() - 1);
                System.out.println(this.getName() + " is selling ticket, " + ticket.getAmount() + " left");
                try {
                    Thread.sleep(30);
                } catch (Exception e) {

                }
            }
        }
    }
}
